package com.lagou.service.impl;

import com.lagou.pojo.Article;
import com.lagou.repository.ArticleRepository;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleRepository articleRepository;

    //1,new simpleKey()、2,有且只有一个参数时，以这个参数值作为key，3，new simpleKey(pageNum, pageSize)
    @Override
    @Cacheable(value = "article")
    public Page<Article> queryPage(Integer pageNum, Integer pageSize) {
        PageRequest pageRequest = PageRequest.of(pageNum, pageSize);
        Page<Article> page = articleRepository.findAll(pageRequest);

        return page;
    }
}
